In [1]:
%pylab inline
from gpkit import GP, VectorVariable, Variable
import gpkit.interactive
gpkit.interactive.init_printing()
In [2]:
L = Variable("L", 0.1, "years", "system lifetime")
Rmin = 0.997 # minimum system reliability
mlogRmin = Variable("\\mathrm{log}(\\tfrac{1}{R_{min}})",
log(1/Rmin), "-", "log of inverse of system reliability")
n = 3 # number of parts
c = VectorVariable(n, "c", [1, 2, 2], "-", "cost to replace each part, in USD")
q = gpkit.VectorVariable(n, "q", "1/years", "log of inverse of part reliabilities")
L10 = VectorVariable(n, "L_{10}", [1, 3, 1], "years", "L10 lifetimes")
k = array([1.5, 1.5, 2]) # part shape factors; 1.5 is what's used by ISO-281
lam = 4.4828*L10 # Weibull scale factors
x = gpkit.VectorVariable(n, "x", "1/years", "maintenance rate")
In [3]:
gp = gpkit.GP(L*(c*x).sum(),
[q == x*(lam*x)**-k,
q.sum() <= mlogRmin/L,
L*x >= 1])
gp
Out[3]:
In [4]:
sol = gp.solve()
print
print "The optimal schedule, over the lifetime of %.2g years" % sol(L)
print " is to buy each part [ %s ] times" % " ".join(["%.2g" % xi for xi in sol(L*x)])
print " at a total cost of $%.3g" % sol["cost"]
In [5]:
sol["local_model"].flatten()[0]
Out[5]:
In [6]:
from IPython import utils
from IPython.core.display import HTML
import os
def css_styling():
"""Load default custom.css file from ipython profile"""
base = utils.path.get_ipython_dir()
styles = ("<style>\n%s\n</style>" %
open(os.path.join(base,'profile_default/static/custom/custom.css'),'r').read())
return HTML(styles)
css_styling()
Out[6]: